
from langchain_core.messages import RemoveMessage
from core.llm import llm
from core.state import AgentState
from core.tools import tools


def agent_node(state: AgentState) -> dict:
    """消息分发智能体"""
    messages = state["messages"]
    # 过滤已移除的消息
    processable_messages = [msg for msg in messages if not isinstance(msg, RemoveMessage)]

    llm_with_tools = llm.bind_tools(tools)
    response = llm_with_tools.invoke(processable_messages)

    return {"messages": [response]}